package com.sgcc.fj.pmos.e_fj_mall.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.bean.StoreScreenBackBean;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.ListPageUtil;
import com.sgcc.fj.pmos.e_fj_mall.bean.StoreBean;
import com.sgcc.fj.pmos.e_fj_mall.contract.StoreContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class StorePresenter extends BasePresenter<StoreContract.View> implements StoreContract.Presenter {
    @Override
    public void getStoreList(int pageSize, boolean isLoading, String saleMemberNumOrder, String saleEnergyYearOrder, StoreScreenBackBean storeScreenBackBean,String userNumSort) {
        Map<String, Object> params = new HashMap<>();

        if(storeScreenBackBean!=null){
            params.put("owernType", storeScreenBackBean.getOwernType());
            params.put("creditRating", storeScreenBackBean.getCreditRating());
            params.put("geogrregionId", storeScreenBackBean.getGeogrregionId());
            params.put("regcapital", storeScreenBackBean.getRegcapital());
            params.put("saleEnergyYear", storeScreenBackBean.getSaleEnergyYear());
            params.put("saleMemberNum", storeScreenBackBean.getSaleMemberNum());
        }
        params.put("evaScope", "");
        params.putAll(ListPageUtil.getPageInfo(pageSize));
        params.put("membersSdName", "");
        params.put("saleMemberNumOrder", saleMemberNumOrder);
        params.put("saleEnergyYearOrder", saleEnergyYearOrder);
        params.put("userNumSort", userNumSort);

        params.put("comprehensiveSort", "");
        params.put("membersSdId", "BE738C62781AD91447C8516F11B5EC2E");
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_STORE, new MvpNetCallback<StoreBean>(getView(), isLoading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().queryFailed();
            }

            @Override
            public void onResponse(StoreBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().querySuccess(response);
            }
        });
    }
}
